package com.ziven.common.widget.setting;

import android.view.View;

import androidx.annotation.NonNull;

import com.ziven.common.widget.R;
import com.ziven.common.widget.value.Image;
import com.ziven.common.widget.value.Value;

/**
 * @author Ziven
 */
public class RedPointPreferenceItem extends ClickPreferenceItem {

    public boolean isAutoInvisibleRedPoint = true;

    public RedPointPreferenceItem() {
        subIcon = Image.drawableId(R.drawable.drawable_setting_item_red_point);
    }

    @Override
    public void afterDataLoaded() {
        if(isAutoInvisibleRedPoint) {
            setRelatedIds(id);
        }
    }

    @Override
    public Value effect() {
        if(isAutoInvisibleRedPoint) {
            subIcon = null;
            if(getBoolean()) {
                subIcon = Image.drawableId(R.drawable.drawable_setting_item_red_point);
            }
        }
        return super.effect();
    }

    @Override
    public boolean onItemClick(BasePreferenceItem data, int position, @NonNull View view) {
        if(isAutoInvisibleRedPoint && getBoolean()) {
            putBoolean(false);
        }
        return super.onItemClick(data, position, view);
    }
}
